package com.example.esredisrabbitmqdemo.conf;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * 配置单条消息过期时间
 */
public class ExpirationMessagePostProcessor implements MessagePostProcessor {

    private String ttl;

    public ExpirationMessagePostProcessor(String ttl){
        this.ttl = ttl;
    }


    //手动设置过期时间
    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setExpiration(ttl);
        return message;
    }
}
